//
//  SingleDetailTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/7.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class SingleDetailTableViewCell: UITableViewCell {

    @IBOutlet weak var totalMoney: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var specLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    func reload(withModel model:ListModel){
        let totalMoney = model.price * Double(model.num)
        let str = "小计：¥" + "\(totalMoney)"
        var attri = NSMutableAttributedString.init(string: str)
        attri.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 11)], range: NSString.init(string: str).range(of: "￥"))
        attri = NSMutableAttributedString.init(attributedString: attri)
        attri.addAttributes([NSAttributedStringKey.foregroundColor:UIColor.init(hexColor: "#ed4848")], range: NSString.init(string: str).range(of: "￥"+"\(totalMoney)"))
        attri = NSMutableAttributedString.init(attributedString: attri)
        attri.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 11)], range: NSString.init(string: str).range(of: ".00"))
        attri = NSMutableAttributedString.init(attributedString: attri)
        attri.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 16)], range: NSString.init(string: str).range(of: "\(totalMoney)".getPriceInteger()))
        self.totalMoney.attributedText = attri
        self.timeLabel.text = model.createTime.timeStampToString(timeFormat: "YYYY-MM-dd HH:mm:ss")
        self.price.text = "采购单价：¥\(model.price)/斤"
        self.specLabel.text = (model.goods?.specDesc == "" ? "" : (model.goods?.specDesc)! + "×") + "\(model.num)" + (model.goods?.spec)!
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
